package com.boyi.converter;

import org.springframework.format.AnnotationFormatterFactory;
import org.springframework.format.Formatter;
import org.springframework.format.Parser;
import org.springframework.format.Printer;

import java.text.ParseException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

/**
 * @author tingwen
 * @description 时间转换器
 * @date 2019-09-07 13:35
 **/
public class SensitiveFieldFormatterFactory implements AnnotationFormatterFactory<SensitiveEncrypt> {

  @Override
  public Set<Class<?>> getFieldTypes() {
    return new HashSet<>(Arrays.asList(new Class<?>[] {String.class}));
  }

  @Override
  public Printer<String> getPrinter(SensitiveEncrypt sensitiveEncrypt, Class<?> aClass) {
    return new SensitiveFieldFormatter();
  }
  @Override
  public Parser<String> getParser(SensitiveEncrypt sensitiveEncrypt, Class<?> aClass) {
    return new SensitiveFieldFormatter();
  }

  final class SensitiveFieldFormatter implements Formatter<String> {

    @Override
    public String parse(String s, Locale locale) throws ParseException {
      System.out.println("s = " + s);
      return "null";
    }

    @Override
    public String print(String s, Locale locale) {
      System.out.println("s = " + s);
      return "null";
    }
  }
}